package com.webchat.chat.configurer;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import java.util.Properties;

import static com.webchat.chat.core.tools.ProjectConstant.MAPPER_INTERFACE_REFERENCE;
import static com.webchat.chat.core.tools.ProjectConstant.MAPPER_PACKAGE;

/**
 * Created by Owner on 2018/6/27.
 */
@Configuration
public class MyBatisScannerConfigurer {

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
        mapperScannerConfigurer.setBasePackage(MAPPER_PACKAGE); //Mapper所在包

        //配置通用Mapper
        Properties properties = new Properties();
        properties.setProperty("mappers", MAPPER_INTERFACE_REFERENCE);//Mapper插件基础接口的完全限定名

        properties.setProperty("notEmpty", "true");//insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''

        properties.setProperty("IDENTITY", "SELECT UUID()");//使用UUID作為主鍵
        properties.setProperty("ORDER","BEFORE");//将查询主键作为前置操作

        mapperScannerConfigurer.setProperties(properties);

        return mapperScannerConfigurer;
    }

}
